import java.util.Hashtable;
import java.util.Vector;


class P325_39643 {

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

	
	static Hashtable map = new Hashtable();
	
	public static void main(String[] args) {
		
//		map.put("n", "n");
		map.put("nen", "nen");
		map.put("npn", "npn");
		map.put("sn", "sn");
		map.put("snpn", "snpn");
		map.put("npnen", "npnen");
		map.put("snpnen", "snpnen");
		map.put("npnesn", "npnesn");
		map.put("snpnesn", "snpnesn");
		map.put("snen", "snen");
		map.put("nesn", "nesn");
		
		String line = readLn();
		
		while (!"*".equals(line)) {
			System.out.print(line);
			
			process(line);
			
			line = readLn();
		}
		
	}


	private static void process(String line) {
		Vector v = new Vector();
		
		for (int k = 0; k < line.length(); k++) {
			
			char c = line.charAt(k);
			
			if (c == '+' || c == '-') v.addElement("s");
			else if (c >= '0' && c <= '9') {
				
				String x = c + "";
				k++;
				
				while (k < line.length() && line.charAt(k) >= '0' && line.charAt(k) <= '9') {
					
					x = x + line.charAt(k);
					k++;
				}
				
				v.addElement("n");
				k--;
				
			}
			else if (c == '.') {
				v.addElement("p");
			} 
			
			else if (c == 'E' || c == 'e') {
				v.addElement("e");
			}
			else {
				System.out.println(" is illegal.");
				return;
			}
		}
		
		StringBuffer sb = new StringBuffer();
		
		for (int k = 0; k < v.size(); k++) {
			sb.append(v.elementAt(k));
		}
//		System.out.println();
//		System.out.println(sb);
		
		if (map.get(sb.toString()) != null) {
			System.out.println(" is legal.");
		} else {
			System.out.println(" is illegal.");
		}
		
		
	}
	
}
